<!--
 * 配置管理
 * @author luguoxiang
 * @date 2023-03-27
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
-->
<template>
  <lg-table :schema="fieldList" v-bind="tableProps" actionbar>
    <template #toolbar-left>
      <t-button @click="editRef.open()">新增</t-button>
    </template>
    <template #actionbar="{ row }">
      <btn-row-update @click="editRef.open(row)" />
      <btn-row-remove @click="remove(row.code)" />
    </template>
  </lg-table>
  <edit ref="editRef" @ok="reload(1)" />
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { LgTable, useTable } from '@/soar';
import api from '@/api/sysConfig';
import fieldList from './schema';
import Edit from './Edit.vue';

const code = 'login';
const model = ref({});
const form = ref();
const editRef = ref();

function load() {
  api.get(code).then((res) => {
    model.value = res ?? {};
  });
}

const { tableProps, remove, reload } = useTable<any>({
  api,
  rowKey: 'code',
  props: {
    paramsHandle(params) {
      params.$soarQuery['type-eq'] = 1;
    },
  },
});

defineExpose({
  submit() {
    form.value.validate().then(() => {
      api.set(code, model.value);
    });
  },
  reset() {
    return form.value.reset();
  },
});

onMounted(() => {
  load();
});
</script>
